/* Dinic应用
*/

#define DEBUG
#pragma GCC optimize("O1,O2,O3,Ofast")
#pragma GCC optimize("no-stack-protector,unroll-loops,fast-math,inline")
#pragma GCC target("avx,avx2,fma")
#pragma GCC target("sse,sse2,sse3,sse4,sse4.1,sse4.2,ssse3")

#include <iostream>
#include <cstring>
using namespace std;

const int N = 110, M = 5210, INF = 0x3f3f3f3f;
int m, n, S, T;
int h[N], e[M], f[M], ne[M], idx;
int q[N], d[N], cur[N];
// d[i]: 分层图每个点的深度
// cur[i]：弧优化

void AddEdge(int a, int b, int c)
{
    e[idx] = b, f[idx] = c, ne[idx] = h[a], h[a] = idx++;
    e[idx] = a, f[idx] = 0, ne[idx] = h[b], h[b] = idx++;

}

bool bfs()
{
    int hh = 0, tt = -1;
    memset(d, -1, sizeof d);
    q[++tt] = S, d[S] = 0, cur[S] = h[S];
    while(hh <= tt)
    {
        int u = q[hh++];
        for(int i = h[u]; ~i; i = ne[i])
        {
            int v = e[i];
            if(d[v] == -1 && f[i]) //存在增广路径
            {
                //printf("u%d-(%d)->v%d\n", u, f[i], v);
                d[v] = d[u]+1;
                cur[v] = h[v];
                if(v == T) return true;
                q[++tt] = v;
            }
        }
    }
    return false;
}

int find(int u, int limit)
{
    if(u == T) return limit;
    int flow = 0;

    for(int i = cur[u]; ~i && flow < limit; i = ne[i], cur[u] = i)
    { 
        
        int v = e[i];
        if(d[v] == d[u] + 1 && f[i])
        {
            int t = find(v, min(f[i],limit-flow));
            if(!t) d[v] = -1;
            f[i] -= t, f[i^1] += t, flow += t;
            //printf("i:%d f[i]:%d\n", i, f[i]);
        }
    }
    return flow;
}

int Dinic()
{
    int r = 0, flow;
    while(bfs())
        while(flow = find(S, INF)) r += flow;
    return r;
}

signed main()
{
    #ifdef DEBUG
        freopen("./in.txt", "r", stdin);
    #else
        ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    #endif

    cin >> m >> n;
    S = 0, T = n+1;
    memset(h, -1, sizeof h);
    for(int i = 1; i <= m; i++) AddEdge(S, i, 1);
    for(int i = m+1; i <= n; i++) AddEdge(i, T, 1);

    int a, b;
    while(cin >> a >> b, a != -1)
        AddEdge(a, b, 1);


    printf("%d\n", Dinic());

    for(int i = 0; i < idx; i+=2){
        if(e[i] > m && e[i] <= n && !f[i]) //当前这条边有流量
            printf("%d %d\n", e[i^1], e[i]);
    }

    return 0;
}